import pandas as pd
import smtplib
from email.mime.text import MIMEText
from email.header import Header

# 邮件内容
df = pd.read_excel("数据-学生成绩表.xlsx", index_col='姓名')
html = f""" <h1> 学生成绩统计数据 </h1> {df.describe().to_html()}"""
message = MIMEText(html, 'html', 'utf-8')

# 发送地址和接收地址
from_email, to_email = "693609645@qq.com", "693609645@qq.com"
# 邮件信息
message['Subject'] = Header("【自动邮件】学生成绩表统计数据", 'utf-8')
message['From'], message['To'] = from_email, to_email

# 使用QQ邮箱的服务，发送邮件
smtpObj = smtplib.SMTP_SSL("smtp.qq.com", 465)
smtpObj.login(from_email, "hidrnhkxpoffbbgb")
smtpObj.sendmail(from_email, [to_email], message.as_string())
smtpObj.quit()
print('邮件发送成功')
